﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using EXT;
using System.Windows.Forms;

namespace BanHangCshap.DanhMuc.gkhtdl63.Nghiemthu
{
    public partial class frmSoluongNhiemthu : Form
    {
        int x, y;
        long id;
        decimal Soluong;
        decimal SoluongDaNghiemthu;
        string Ma_QCBoSanpham;
        public frmSoluongNhiemthu(int x, int y,string Ma_QCBoSanpham, long id, decimal Soluong, decimal SoluongDaNghiemthu)
        {
            this.x = x;
            this.y = y;
            this.id = id;
            this.Soluong = Soluong;
            this.Ma_QCBoSanpham = Ma_QCBoSanpham;
            this.SoluongDaNghiemthu = SoluongDaNghiemthu;
            InitializeComponent();
        }

        public frmSoluongNhiemthu()
        {
            InitializeComponent();
        }

        private void frmSoluongNhiemthu_Load(object sender, EventArgs e)
        {
            this.Location = new Point(x, y-60);
            txtSoluong.EditValue = Soluong - SoluongDaNghiemthu;
        }

        public event MyEvent_LoadData Tailai = null;

        private void btnDongy_Click(object sender, EventArgs e)
        {
            if (DevExpress.XtraEditors.XtraMessageBox.Show("Bạn muốn nghiệm thu với số lượng "+txtSoluong.Text+" không?","Thông báo",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
            {
                decimal xz = Math.Round(SoluongDaNghiemthu, 1);
                if (txtSoluong.EditValue.ToDecimal()>Soluong-xz)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("Vượt số lượng có thể nghiệm thu là " + (Soluong-SoluongDaNghiemthu) .ToString("n2"), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (txtSoluong.EditValue.ToFloat() <=0)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("Số lượng nghiệm thu phải lớn hơn 0", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                Class.gkhtdl63.BLL.ChitietDuanBLL xlChitietDuanBLL = new BanHangCshap.Class.gkhtdl63.BLL.ChitietDuanBLL();
                Class.gkhtdl63.BLL.QCBoSanphamBLL xlQCBoSanphamBLL = new BanHangCshap.Class.gkhtdl63.BLL.QCBoSanphamBLL();
                xlQCBoSanphamBLL.QCBoSanPham_CapnhatSoluong(txtSoluong.EditValue.ToFloat(), Ma_QCBoSanpham);
                if (xlChitietDuanBLL.ChitietDuan_CapnhatSoluongDanghiemthu(id,txtSoluong.EditValue.ToFloat()))
                {
                    if (Tailai!=null)
                    {
                        Tailai(this, new ELoadData() { IsLoadData = true, Data = txtSoluong.EditValue });
                    }
                    this.Close();
                }
            }
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
